package org.erp.procurement.controller;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.domain.Result;
import org.erp.common.page.DataPageResp;
import org.erp.common.page.PageQueryModel;
import org.erp.procurement.convert.MiniOrderConvert;
import org.erp.procurement.entity.bo.MiniOrderAddBo;
import org.erp.procurement.entity.bo.MiniOrderConfirmBo;
import org.erp.procurement.entity.bo.MiniOrderQueryBo;
import org.erp.procurement.entity.bo.OrderUpdateBo;
import org.erp.procurement.entity.vo.MiniOrderVo;
import org.erp.procurement.service.MiniOrderService;
import org.springframework.web.bind.annotation.*;

import static org.erp.common.domain.Result.success;

/**
 * 线上采购订单控制层
 *
 * @author libin
 * @version 1.0
 * @description: 线上采购订单控制层
 * @date 2025/11/7 17:55
 **/
@Log4j2
@RestController
@AllArgsConstructor
@RequestMapping("/mini/order")
public class MiniOrderController {

    private final MiniOrderService miniOrderService;

    private final MiniOrderConvert miniOrderConvert;

    /**
     * 线上采购订单
     *
     * @param miniOrderQueryBo
     * @return
     */
    @PostMapping("/list")
    public Result<DataPageResp<MiniOrderVo>> miniPageList(@RequestBody MiniOrderQueryBo miniOrderQueryBo) {
        PageQueryModel<MiniOrderVo> queryModel = miniOrderService.miniPageList(miniOrderConvert.boConvertDto(miniOrderQueryBo));
        return success(DataPageResp.of(queryModel.getTotal(), queryModel.getDataList()));
    }

    /**
     * 线上采购订单添加
     *
     * @param miniOrderAddBo
     * @return
     */
    @PostMapping("/save")
    public Result<String> miniSave(@RequestBody MiniOrderAddBo miniOrderAddBo) {
        miniOrderService.miniSave(miniOrderAddBo);
        return success();
    }

    /**
     * 线上采购订单确认收货
     *
     * @param MiniOrderConfirmBo
     * @return
     */
    @PostMapping("/confirmReceipt")
    public Result<String> miniConfirmReceipt(@RequestBody MiniOrderConfirmBo MiniOrderConfirmBo) {
        miniOrderService.miniConfirmReceipt(MiniOrderConfirmBo);
        return success();
    }

    /**
     * 线上采购订单确认报价
     *
     * @param
     * @return
     */
    @PutMapping("/quote")
    public Result<String> miniQuote(@RequestParam("orderNo") String orderNo) {
        miniOrderService.miniQuote(orderNo);
        return success();
    }

    /**
     * 修改采购数量
     *
     * @param orderUpdateBo
     * @return
     */
    @PutMapping("/update")
    public Result<String> updatePurchaseQuantity(@RequestBody OrderUpdateBo orderUpdateBo) {
        miniOrderService.updatePurchaseQuantity(orderUpdateBo);
        return success();
    }

    /**
     * 线上采购订单取消订单
     *
     * @param orderNo
     * @return
     */
    @PutMapping("/cancel")
    public Result<String> miniCancel(@RequestParam("orderNo") String orderNo) {
        miniOrderService.miniCancel(orderNo);
        return success();
    }

    /**
     * 线上采购订单确认订单
     *
     * @param orderNo
     * @return
     */
    @PutMapping("/confirm")
    public Result<String> miniConfirm(@RequestParam("orderNo") String orderNo) {
        miniOrderService.miniConfirm(orderNo);
        return success();
    }

}
